package com.lanyam.travel.base.service.impl;


import com.lanyam.travel.base.entity.CashSetting;
import com.lanyam.travel.base.entity.vo.CashSettingVo;
import com.lanyam.travel.base.dao.CashSettingMapper;
import com.lanyam.travel.base.service.ICashSettingService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;


@Service
@Transactional
@Slf4j
public class CashSettingServiceImpl implements ICashSettingService {

    @Resource
    private CashSettingMapper cashSettingMapper;

    @Override
    public IPage<CashSettingVo> getPageCashSetting (Map<String, Object> queryMap, Integer page, Integer rows) {
        Page<CashSettingVo> pageSize = new Page<CashSettingVo>(page, rows);
        Page<CashSettingVo> pageInfo = cashSettingMapper.getPage(pageSize, queryMap);
        return pageInfo;
    }

    @Override
    public void addCashSetting(CashSetting cashSetting) {
        cashSettingMapper.insert(cashSetting);
    }

    @Override
    public void updateCashSetting(CashSetting cashSetting) {
        int count = cashSettingMapper.getCount();
        if (count > 0) {
            cashSettingMapper.updateSettingData(cashSetting);
        } else {
            cashSetting.setId(UUID.randomUUID().toString().replaceAll("-",""));
            cashSettingMapper.insert(cashSetting);
        }
    }

    @Override
    public void delById(String id) {
        cashSettingMapper.delById(id);
    }

    @Override
    public CashSetting getSettingData() {
        CashSetting settingData = cashSettingMapper.getSettingData();
        return settingData;
    }
}